﻿using System;
using System.Collections.Generic;
using UnityEngine;

// Token: 0x02000280 RID: 640
[RequireComponent(typeof(Rigidbody))]
public class MapCollision : MonoBehaviour
{
	// Token: 0x0600109F RID: 4255 RVA: 0x00069E20 File Offset: 0x00068020
	private void Awake()
	{
		this.cols = base.gameObject.GetComponents<Collider>();
		if (this.cols == null)
		{
			MonoBehaviour.print("当たり判定がない");
		}
		this.hitCnt = 0;
		Renderer[] componentsInChildren = base.gameObject.GetComponentsInChildren<Renderer>();
		foreach (Renderer rend in componentsInChildren)
		{
			this.dataList.Add(new MapCollision.Data(rend));
		}
		this.show = true;
	}

	// Token: 0x060010A0 RID: 4256 RVA: 0x00069E98 File Offset: 0x00068098
	private void Start()
	{
		this.cam = Camera.main;
		this.hitCnt = 0;
	}

	// Token: 0x060010A1 RID: 4257 RVA: 0x00069EAC File Offset: 0x000680AC
	private void Update()
	{
		this.ShowCalc();
	}

	// Token: 0x060010A2 RID: 4258 RVA: 0x00069EB4 File Offset: 0x000680B4
	public void Show()
	{
		if (this.show)
		{
			return;
		}
		this.show = true;
		foreach (MapCollision.Data data in this.dataList)
		{
			data.Show();
		}
	}

	// Token: 0x060010A3 RID: 4259 RVA: 0x00069F24 File Offset: 0x00068124
	public void Hide()
	{
		if (!this.show)
		{
			return;
		}
		this.show = false;
		foreach (MapCollision.Data data in this.dataList)
		{
			data.Hide(this.setLayer);
		}
	}

	// Token: 0x060010A4 RID: 4260 RVA: 0x00069F98 File Offset: 0x00068198
	private void OnTriggerEnter(Collider other)
	{
		if (other.gameObject == null)
		{
			MonoBehaviour.print("other.gameObject == null");
		}
		if (this.cam == null)
		{
			MonoBehaviour.print("cam == null");
			return;
		}
		if (this.cam.gameObject == null)
		{
			MonoBehaviour.print("cam.gameObject == null");
		}
		if (other.gameObject == null || this.cam.gameObject == null)
		{
			return;
		}
		if (other.gameObject == this.cam.gameObject)
		{
			this.hitCnt = 1;
			this.ShowCalc();
		}
	}

	// Token: 0x060010A5 RID: 4261 RVA: 0x0006A04C File Offset: 0x0006824C
	private void OnTriggerExit(Collider other)
	{
		if (other.gameObject == null)
		{
			MonoBehaviour.print("other.gameObject == null");
		}
		if (this.cam.gameObject == null)
		{
			MonoBehaviour.print("cam.gameObject == null");
		}
		if (other.gameObject == null || this.cam.gameObject == null)
		{
			return;
		}
		if (other.gameObject == this.cam.gameObject)
		{
			this.hitCnt = 0;
			this.ShowCalc();
		}
	}

	// Token: 0x060010A6 RID: 4262 RVA: 0x0006A0E4 File Offset: 0x000682E4
	private void ShowCalc()
	{
		bool flag = true;
		bool flag2 = !(this.cam != null) || ConfigData.autoHideObstacle;
		bool flag3 = flag;
		if (flag2 && this.hitCnt != 0)
		{
			flag3 = false;
		}
		if (flag3)
		{
			this.Show();
		}
		else
		{
			this.Hide();
		}
	}

	// Token: 0x040011CD RID: 4557
	private Collider[] cols;

	// Token: 0x040011CE RID: 4558
	private Plane plane;

	// Token: 0x040011CF RID: 4559
	private Camera cam;

	// Token: 0x040011D0 RID: 4560
	private int hitCnt;

	// Token: 0x040011D1 RID: 4561
	private bool show;

	// Token: 0x040011D2 RID: 4562
	private List<MapCollision.Data> dataList = new List<MapCollision.Data>();

	// Token: 0x040011D3 RID: 4563
	public int setLayer = 16;

	// Token: 0x02000281 RID: 641
	private class Data
	{
		// Token: 0x060010A7 RID: 4263 RVA: 0x0006A13C File Offset: 0x0006833C
		public Data(Renderer rend)
		{
			this.rend = rend;
			this.layer = rend.gameObject.layer;
		}

		// Token: 0x060010A8 RID: 4264 RVA: 0x0006A15C File Offset: 0x0006835C
		public void Show()
		{
			this.rend.gameObject.layer = this.layer;
		}

		// Token: 0x060010A9 RID: 4265 RVA: 0x0006A174 File Offset: 0x00068374
		public void Hide(int setLayer)
		{
			this.rend.gameObject.layer = setLayer;
		}

		// Token: 0x040011D4 RID: 4564
		private Renderer rend;

		// Token: 0x040011D5 RID: 4565
		private int layer;
	}
}
